package fr.cephb.joperon.structures;

import java.io.Serializable;

import fr.cephb.joperon.core.bio.AcidNucleicUtil;
import fr.cephb.util.JSONBuilder;
import fr.cephb.util.JSONizable;

/**
 * GTypes
 * Genotype alleles
 */
public class GTypes
implements Serializable,JSONizable
	{
	private static final long serialVersionUID = 1L;
	/**
     * code
     * Genotype alleles.
     * it is stored as a int16_t
     */
     private short code;
     
     
     public GTypes()
    	 {
    	 }
     
     public GTypes(short code)
    	 {
    	 this.code=code;
    	 }
     
     
     
    /**
     * getter for code
     * Genotype alleles.
     * @return the value of code
     */
    public short getCode()
            {
            return this.code;
            }
    /**
 * setter for code
 * Genotype alleles.
 * @param  code the new value of code
 */
    public void setCode(short code)
            {
            this.code=code;
            }
    
    @Override
    public boolean equals(Object obj)
    	{
    	if(obj==this) return true;
    	if(obj==null || !(obj instanceof GTypes)) return false;
    	return GTypes.class.cast(obj).getCode()==this.getCode();
    	}
    
    @Override
    public int hashCode()
    	{
    	return code;
    	}
    
	@Override
	public String toJSON()
		{
		return new JSONBuilder().
			put("code", getCode()).
			put("alleles",getAlleles()).
			getString();
		}
	
	public String getAlleles()
        {
        return AcidNucleicUtil.decode_genotype(getCode());
        }

	@Override
	public String toString()
		{
		return toJSON();
		}
	}
